﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UIElements;
using UnityEngine.UI;
using Image = UnityEngine.UI.Image;

/**
 * 控制UI
 */

public class UIControl : MonoBehaviour
{
    public int gemNum;
    public int health;
    public Text t_gemNum;

    public Text t_Health;

    [SerializeField] private GameObject u_Gameover, u_StageClear,u_start;
    // Start is called before the first frame update
    void Awake()
    {
        
        u_Gameover = GameObject.Find("GameOver");
        u_StageClear = GameObject.Find("StageClear");
        u_start = GameObject.Find("Start");
        u_Gameover.SetActive(false);
        u_StageClear.SetActive(false);
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    static public bool ComeToTransparent(Image g,float speed)
    {
        float Alpha = g.color.a;
        if (Alpha > 0.01)
        {
            Alpha += Time.deltaTime * speed*-1;
            g.color = new Color(g.color.r,g.color.g,g.color.b,Alpha);
            return false;
        }

        return true;
    }
    static public bool ComeToDisTransparent(Image g,float speed)
    {
        float Alpha = g.color.a;
        if (Alpha < 1)
        {
            Alpha += Time.deltaTime * speed;
            g.color = new Color(g.color.r,g.color.g,g.color.b,Alpha);
            return false;
        }
        return true;
    }

    static public bool ComeToTransparent(Text g,float speed)
    {
        float Alpha = g.color.a;
        if (Alpha > 0.01)
        {
            Alpha += Time.deltaTime * speed*-1;
            g.color = new Color(g.color.r,g.color.g,g.color.b,Alpha);
            return false;
        }

        return true;
    }
    static public bool ComeToDisTransparent(Text g,float speed)
    {
        float Alpha = g.color.a;
        if (Alpha < 1)
        {
            Alpha += Time.deltaTime * speed;
            g.color = new Color(g.color.r,g.color.g,g.color.b,Alpha);
            return false;
        }
        return true;
    }

    public void SetGem(int a)
    {
        t_gemNum.text = ":" + a;
    }

    public void SetHealth(int d)
    {
        t_Health.text = ":" + d;
    }

    public void StartGame()
    {
        gameObject.SetActive(true);
        u_Gameover.SetActive(false);
        u_StageClear.SetActive(false);
        t_gemNum = GameObject.Find("GEM").GetComponentInChildren<Text>();
        t_Health = GameObject.Find("HEALTH").GetComponentInChildren<Text>();
    }

    public IEnumerator GameOver()
    {
        u_Gameover.SetActive(true);
        u_start.SetActive(true);
        yield return new WaitForSeconds(1.25f);
        StartButton.ISOVER = true;
    }

    public IEnumerator GameNext()
    {
        u_StageClear.SetActive(true);
        u_start.SetActive(true);
        yield return new WaitForSeconds(1.25f);
        StartButton.ISNEXT = true;
    }
}
